package com.company.woye.console.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.company.woye.R;
import com.company.woye.console.activity.CheckoutConsoleActivity;
import com.company.woye.console.entity.LoadTXMEntity;

import java.util.List;

public class LoadTXMAdapter extends RecyclerView.Adapter<LoadTXMAdapter.ViewHolder> {


    private LayoutInflater inflater;
    private Context mContext;
    private List<LoadTXMEntity> list;
    private OnItemClickListener onItemClickListener;


    public LoadTXMAdapter(Context context,List<LoadTXMEntity> list,OnItemClickListener onItemClickListener) {
        this.inflater= LayoutInflater.from(context);
        this.mContext=context;
        this.list=list;
        this.onItemClickListener=onItemClickListener;
    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_load_txm, null);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        if (!TextUtils.isEmpty(list.get(position).getTXM())){
            holder.oneTextView.setText(list.get(position).getTXM());
        }
        holder.oneTextView.setOnClickListener(v -> {
            onItemClickListener.onItemClick(position,list.get(position).getTXM());
        });
    }


    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemCount() {
        return list.size();
    }



    class ViewHolder extends RecyclerView.ViewHolder{

        private TextView oneTextView;
        public ViewHolder(View view) {
            super(view);
            oneTextView=view.findViewById(R.id.tv_cjl_one);
        }
    }
    public  interface OnItemClickListener{
        void onItemClick(int position, String data);
    }
}
